package com.mall.web.vo;

import org.apache.commons.lang3.StringUtils;

import com.mall.constant.ReqAttributeKey;

/**
 * ajax请求的json返回对象封装 Created by Hays on 14/11/9.
 */
public class ResponseEntity<T> extends AbstractJsonEntity {
	private T data;

	public ResponseEntity() {
		super();
	}

	public ResponseEntity(String code, String msg, T data) {
		super(code, msg);
		this.data = data;
	}

	public ResponseEntity(String code, String msg) {
		super(code, msg);
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	/**
	 * 错误返回初始化
	 * 
	 * @param t
	 */
	public void initErrorResponseEntity(T t, String errMessage) {
		this.code = ReqAttributeKey.CODE_HTTP_ERROR_CODE;
		if (StringUtils.isNotBlank(errMessage)) {
			this.message = errMessage;
		} else {
			this.message = ReqAttributeKey.CODE_HTTP_ERROR_MESSAGE;
		}
		this.data = t;
	}

	/**
	 * 成功返回初始化
	 * 
	 * @param t
	 */
	public void initSuccResponseEntity(T t, String succMessage) {
		this.code = ReqAttributeKey.CODE_HTTP_SUCCESS_CODE;
		if (StringUtils.isNotBlank(succMessage)) {
			this.message = succMessage;
		} else {
			this.message = ReqAttributeKey.CODE_HTTP_SUCCESS_MESSAGE;
		}
		this.data = t;
	}

}
